#include "LabelAligned.h"
#include "../../common/utils/UtilString.h"

LabelAligned::LabelAligned(std::string message, Color colorBgr, Widget* parent, int x, int y) :
	Widget(colorBgr, UtilString::pxSize(message), DEFAULT_FONT_SIZE, x, y,
			parent) {

	this->textSurface = SurfaceUtils::renderText(message);
}

LabelAligned::LabelAligned(std::string message, Color colorBgr, Widget* parent, int x, int y,
		int fontSize, int r, int g, int b) :
	Widget(colorBgr, UtilString::pxSize(message), DEFAULT_FONT_SIZE, x, y,
			parent) {

	this->textSurface = SurfaceUtils::renderText(message, fontSize, r, g, b);
}

LabelAligned::LabelAligned(std::string message, int fontSize, Widget* parent, int x, int y) :
	Widget(x, y, NULL, parent) {

	this->textSurface = SurfaceUtils::renderText(message, fontSize);
}

LabelAligned::LabelAligned(std::string message, Widget* parent, int x, int y) :
	Widget(x, y, NULL, parent) {

	this->textSurface = SurfaceUtils::renderText(message);
}

LabelAligned::LabelAligned(std::string message, int fontSize, Widget* parent, int x, int y,
		int r, int g, int b) :
	Widget(x, y, NULL, parent) {
	this->textSurface = SurfaceUtils::renderText(message, fontSize, r, g, b);
}

void LabelAligned::showOn(SDL_Surface* surface) {
	SDL_Rect textRect;
	textRect.w = textSurface->w;
	textRect.h = textSurface->h;

	if (this->surface) {
		textRect.x = 10;
		textRect.y = (this->parcel->height /2) - (textRect.h / 2);
		SDL_BlitSurface(this->textSurface, NULL, this->surface, &textRect);
	} else {
		textRect.x = 10;
		textRect.y = this->parcel->posY - this->textSurface->h / 2;
		SDL_BlitSurface(this->textSurface, NULL, surface, &textRect);
	}

	Widget::showOn(surface);
}

Parcel* LabelAligned::getBoundaries() {
	if (this->surface == NULL)
		return SurfaceUtils::getBoundaries(this->textSurface);

	return Widget::getBoundaries();
}

LabelAligned::~LabelAligned() {
	SDL_FreeSurface(textSurface);
}
